﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class OffsetingCost : Acms.AcmsControls.ContentControls.Admin.BaseCustomAdminControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataBind();
        }
    }

    public override void DataBind()
    {
        var factory = new CarbonExchange.Bll.OffsettingCostFactory();
        var item = factory.Get();
        txtCost.Text = item.Cost.ToString("0.00");
        ViewState["CID"] = item.CID;
        base.DataBind();
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        if(Page.IsValid)
        {
            var factory = new CarbonExchange.Bll.OffsettingCostFactory();
            var item = factory.Get();
            if (item.CheckConcurent(ViewState["CID"]))
            {
                try
                {
                    item.Cost = decimal.Parse(txtCost.Text);
                }
                catch (FormatException)
                {
                }
                factory.Save(item);
            }
            else
            {
                DataBind();
                lblConcurencyError.Visible = true;
            }
        }
    }
}
